package org.brian.webscrape;

import java.io.IOException;
import java.text.ParseException;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class CLCitiesParser {

	public static final String APT = "/apa";
	
	public static void main(String [] args) throws IOException, ParseException{
		
		String globalUrl = "http://www.craigslist.org";
		Document doc = CLScrape.getDocForUrl(globalUrl);
		//Elements states = doc.getElementsByClass("state_delimiter");
		Elements states = doc.getElementsByTag("ul");
		System.out.println("states.size "+states.size());
		
		
		for(Element state : states){
			Elements eles = state.getElementsByTag("a");
			for(Element ele : eles){
				CLScrape scraper = new CLScrape();
				String stateUrl = ele.attr("href");
				if(stateUrl != null){
					scraper.quickScrape(stateUrl + APT);
					System.out.println(ele.html()+ "  N:"+scraper.getNumberOfPosts() + " mean:"+scraper.getMeanPrice());
				}
			}			
		}
		
	}
}
